package yt.spider;


import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.format.Time;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

/**
 * Created by 小呆呆 on 2018/1/24.
 */

public class ReadingActivity extends AppCompatActivity {
    private TextView system ;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去掉状态栏，使用自定义View
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.reading);

        //new LittleFunction(this).showTime();
        //hideBottomUIMenu();  //隐藏虚拟按键
        showTime();         //显示左下角系统当前时间
        showBattery();     //显示右下角系统当前电量
     }

    /** * 隐藏虚拟按键，并且全屏 */
    protected void hideBottomUIMenu() {
        //隐藏虚拟按键，并且全屏
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
            View v = this.getWindow().getDecorView();
            v.setSystemUiVisibility(View.GONE);
        } else if (Build.VERSION.SDK_INT >= 19) { //for new api versions.
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }
    }

    //显示系统时间
    protected void showTime(){
        String sminute;
        Time t = new Time();
        t.setToNow();
        int hour = t.hour;
        int minute = t.minute;
        if(minute<10) {  //使小于10的分钟数，以0X显示
            sminute = Integer.toString(minute);
            sminute = "0" + sminute;
        }else {
            sminute= Integer.toString(minute);
        }

        system = (TextView)findViewById(R.id.system_time);
        system.findViewById(R.id.system_time);
        system.setText(hour + ":"+ sminute);
    }

    //显示当前手机电量
    protected void showBattery(){
        Intent batteryInfoIntent = getApplicationContext() .registerReceiver
                ( null , new IntentFilter( Intent.ACTION_BATTERY_CHANGED ) ) ;
        int level = batteryInfoIntent.getIntExtra( "level" , 0 );//电量（0-100）

        //batteryView = (BatteryView)findViewById(R.id.battery_view);
        system = (TextView)findViewById(R.id.system_battery);
        system.findViewById(R.id.system_time);
        system.setText(level + "");
    }
}
